//
//  GTGTUserCenterHeaderView.m
//  globalTranslate
//
//  Created by 陈镇 on 2025/8/11.
//

#import "GTGTUserCenterHeaderView.h"

@interface GTGTUserCenterHeaderView ()

@property(nonatomic,strong) UIImageView *header;
@property(nonatomic,strong) QMUILabel *userName;
@property(nonatomic,strong) UIImageView *vipBtn;


@property(nonatomic,strong) NSArray *itemImages;


@end
@implementation GTGTUserCenterHeaderView

-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        
        self.backgroundColor = UIColorWhite;
        
        [self addSubview:self.header];
        [self addSubview:self.userName];
//        [self addSubview:self.vipBtn];
        
        
        self.height = self.header.bottom + 30;
        
//        [self createButton];
        
        
    
    }
    return self;
}


-(NSArray *)itemImages{
    if (!_itemImages) {
        _itemImages = @[@"user_center_t",@"user_center_v",@"user_center_c",@"user_center_p"];
    }
    return _itemImages;
}

-(UIImageView *)header{
    if (!_header) {
        _header = [[UIImageView alloc] initWithFrame:CGRectMake(20, 20, 50, 50)];
        [_header sl_cornerRadius:25];
//        _header.backgroundColor = UIColorTestRed;
 
    }
    return _header;
}
-(QMUILabel *)userName{
    if (!_userName) {
        _userName = [QMUILabel createTextColor:UIColorHex(#202020) font:SLFontMakeRegular(16) textAlignment:NSTextAlignmentLeft];
        _userName.frame = CGRectMake(_header.right + 15, _header.top, 200, _header.height);
     
    }
    return _userName;
}

-(void)createButton{
    
    CGFloat top =  _header.bottom + 20;
    CGFloat width = 50;
    CGFloat height = width;
    CGFloat left = _header.left;
    CGFloat gap = (self.width - left * 2 - width * self.itemImages.count)/3;
    
    for (int i = 0; i < self.itemImages.count; i++) {
        QMUIButton *btn = [QMUIButton createButtonImageName:self.itemImages[i] selectImageName:self.itemImages[i]];
        [self addSubview:btn];
        btn.frame = CGRectMake(left + (gap + width) *i, top, width, height);
        btn.tag = i;
        [btn addTarget:self action:@selector(clickItem:) forControlEvents:UIControlEventTouchUpInside];
        self.height = btn.bottom + 20;
    }
    
}


-(void)clickItem:(UIButton *)btn{
    if (_delegate && [_delegate respondsToSelector:@selector(userCenterHeaderViewClickItem:)]) {
        [_delegate userCenterHeaderViewClickItem:btn.tag];
    }
}

-(void)setModel:(SLUserInfoModel *)model{
    _model = model;
    [_header setImage:[UIImage imageNamed:model.head]];
    _userName.text = model.userName;
}
@end
